<?php
/**
 * Created by PhpStorm.
 * User: lwt
 * Date: 4/22/19
 * Time: 7:16 PM
 */

namespace app\admin\model;

use think\Db;
use think\Model;

class UserModel extends Model
{
    public static function selectAdmin($data){
        $msg = Db::table("tb_admin")->where("ad_id",$data["ad_id"])->find();
        $isNull = true;
        if (is_array($msg)){
            $isNull = false;
        }
        if ($isNull){
            return 0;
        }else{
            if ($msg["ad_pwd"] == $data["ad_pwd"]){
                Db::table('tb_admin')->where('ad_id', $data["ad_id"])->update($data);
                return 1;
            }else{
                return 2;
            }
        }
    }
    public static function selectAdminMsg($ad_id){
        $msg = Db::table("tb_admin")->where("ad_id",$ad_id)->find();
        $isNull = true;
        if (is_array($msg)){
            $isNull = false;
        }
        if ($isNull){
            $msg1["code"] = 400;
            $msg1["msg"] = "用戶不存在";
            return 0;
        }else{
            unset($msg["ad_pwd"]);
            $msg1["code"] = 200;
            $msg1["msg"] = $msg;
            return $msg1;
        }
    }

    public static function updateAdminMsg($data){
        $msg = Db::table('tb_admin')->where('ad_id', $data["ad_id"])->update($data);
        if ($msg > 0){
            $msg2 = Db::table("tb_admin")->where("ad_id",$data["ad_id"])->find();
            $msg1["code"] = 200;
            unset($msg2["ad_pwd"]);
            $msg1["msg"] = $msg2;
        }else{
            $msg1["code"] = 400;
            $msg1["msg"] = "内容没有更改！";
        }
        return $msg1;
    }
}